<template>
  <div class="app-container">
    <el-table ref="tables" v-loading="loading" stripe :data="list" :default-sort="defaultSort" >
      <el-table-column label="系统日志名称" align="center" prop="name" />
      <el-table-column label="日志文件大小" align="center" prop="filesize" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-download"
            @click="handleDown(scope.row,scope.index)"
          >下载</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { list, downOperlog} from "@/api/monitor/outputlog";

export default {
  name: "Operlog",
  dicts: ['sys_oper_type', 'sys_common_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 默认排序
      defaultSort: {prop: 'operTime', order: 'descending'},
      // 表单参数
      form: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: undefined,
        operName: undefined,
        businessType: undefined,
        status: undefined
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询登录日志 */
    getList() {
      this.loading = true;
      list().then( response => {
          this.list = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 详细按钮操作 */
    handleView(row) {
      this.open = true;
      this.form = row;
    },
    /** 下载日志 */
    //+process.env.VUE_APP_BASE_API
   handleDown(row) {
    window.location.href =  process.env.VUE_APP_BASE_API+'/monitor/sysoutputlog/getsyslogdown?pathstr='+encodeURIComponent(encodeURIComponent(row.path));
    // downOperlog(encodeURIComponent(encodeURIComponent(row.path)));
      // const a = document.createElement('a'); // 创建a标签
      // a.setAttribute('download', row.name);// download属性
      // a.setAttribute('href',downOperlog(encodeURIComponent(encodeURIComponent(row.path))));// href链接
      // a.setAttribute('href', '/dev-api/monitor/sysoutputlog/getsyslogdown?pathstr='+encodeURIComponent(encodeURIComponent(row.path)));// href链接
      // a.setAttribute('href', process.env.VUE_APP_URL+'/monitor/sysoutputlog/getsyslogdown?pathstr='+encodeURIComponent(encodeURIComponent(row.path)));// href链接
      // a.click();// 自执行点击事件
    },
  }
};
</script>

